package com.bcmusic.point.controller;

import com.bcmusic.point.pojo.UserAsset;
import com.bcmusic.point.service.UserAssetService;
import com.github.pagehelper.PageInfo;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/****
 * @Author:admin
 * @Description:
 * @Date 2019/6/14 0:18
 *****/

@RestController
@RequestMapping("/userAsset")
@CrossOrigin
public class UserAssetController {

    @Autowired
    private UserAssetService userAssetService;

    /***
     * UserAsset分页条件搜索实现
     * @param userAsset
     * @param page
     * @param size
     * @return
     */
    @PostMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@RequestBody(required = false)  UserAsset userAsset, @PathVariable  int page, @PathVariable  int size){
        //调用UserAssetService实现分页条件查询UserAsset
        PageInfo<UserAsset> pageInfo = userAssetService.findPage(userAsset, page, size);
        return new Result(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * UserAsset分页搜索实现
     * @param page:当前页
     * @param size:每页显示多少条
     * @return
     */
    @GetMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@PathVariable  int page, @PathVariable  int size){
        //调用UserAssetService实现分页查询UserAsset
        PageInfo<UserAsset> pageInfo = userAssetService.findPage(page, size);
        return new Result<PageInfo>(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * 多条件搜索品牌数据
     * @param userAsset
     * @return
     */
    @PostMapping(value = "/search" )
    public Result<List<UserAsset>> findList(@RequestBody(required = false)  UserAsset userAsset){
        //调用UserAssetService实现条件查询UserAsset
        List<UserAsset> list = userAssetService.findList(userAsset);
        return new Result<List<UserAsset>>(true,StatusCode.OK,"查询成功",list);
    }

    /***
     * 根据ID删除品牌数据
     * @param id
     * @return
     */
    @DeleteMapping(value = "/{id}" )
    public Result delete(@PathVariable Long id){
        //调用UserAssetService实现根据主键删除
        userAssetService.delete(id);
        return new Result(true,StatusCode.OK,"删除成功");
    }

    /***
     * 修改UserAsset数据
     * @param userAsset
     * @param id
     * @return
     */
    @PutMapping(value="/{id}")
    public Result update(@RequestBody  UserAsset userAsset,@PathVariable Long id){
        //设置主键值
        userAsset.setAssetId(id);
        //调用UserAssetService实现修改UserAsset
        userAssetService.update(userAsset);
        return new Result(true,StatusCode.OK,"修改成功");
    }

    /***
     * 新增UserAsset数据
     * @param userAsset
     * @return
     */
    @PostMapping
    public Result add(@RequestBody   UserAsset userAsset){
        //调用UserAssetService实现添加UserAsset
        userAssetService.add(userAsset);
        return new Result(true,StatusCode.OK,"添加成功");
    }

    /***
     * 根据ID查询UserAsset数据
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<UserAsset> findById(@PathVariable Long id){
        //调用UserAssetService实现根据主键查询UserAsset
        UserAsset userAsset = userAssetService.findById(id);
        return new Result<UserAsset>(true,StatusCode.OK,"查询成功",userAsset);
    }

    /***
     * 查询UserAsset全部数据
     * @return
     */
    @GetMapping
    public Result<List<UserAsset>> findAll(){
        //调用UserAssetService实现查询所有UserAsset
        List<UserAsset> list = userAssetService.findAll();
        return new Result<List<UserAsset>>(true, StatusCode.OK,"查询成功",list) ;
    }

}
